package com.joe.demo.chat.server.handler;

import com.joe.demo.chat.message.GroupMembersRequestMessage;
import com.joe.demo.chat.message.GroupMembersResponseMessage;
import com.joe.demo.chat.server.factory.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Set;

/**
 * @Description
 * @Author gaojw
 * @Date 2024-09-03
 */
@ChannelHandler.Sharable
public class GroupMembersRequestMessageHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, GroupMembersRequestMessage groupMembersRequestMessage) throws Exception {
        final Set<String> members = GroupSessionFactory.getGroupSession().getMembers(groupMembersRequestMessage.getGroupName());
        channelHandlerContext.writeAndFlush(new GroupMembersResponseMessage(members));
    }
}
